﻿using LxBasic;
using System.Collections.Generic;

namespace LxCore
{
    public abstract class FieldCombiner
    {
        public abstract class Base<T> where T : struct
        {
            protected List<IField<T>> Fields = new();
            public void Add(IField<T> field)
            {
                if (field == null) return;
                if (field is FieldList.Base<T> fl)
                {
                    foreach (var l in fl.Fields)
                    {
                        Fields.Add(l);
                    }
                }
                else
                {
                    Fields.Add(field);
                }
            }
        }
        public class Double : Base<double>
        {
            public IField<double> Get()
            {
                if (Fields.Count == 0)
                {
                    return ConstField.Double0;
                }
                else if (Fields.Count == 1)
                {
                    return Fields[0];
                }
                else
                {
                    return new FieldList.Double() { Fields = Fields };
                }
            }

        }
        public class Vector : Base<Vector3d>
        {
            public IField<Vector3d> Get()
            {
                if(Fields.Count == 0)
                {
                    return ConstField.Vector0;
                }else if (Fields.Count == 1)
                {
                    return Fields[0];
                }
                else
                {
                    return new FieldList.Vector() { Fields = Fields };
                }
            }
        }
    }
}
